package com.superbytecode.cloud.safety.ratelimit;

import com.superbytecode.cloud.safety.ratelimit.exception.RateLimitException;
import com.superbytecode.cloud.safety.ratelimit.limiter.CustomRateLimiter;
import com.superbytecode.cloud.safety.ratelimit.limiter.IPRateLimiter;
import com.superbytecode.cloud.safety.ratelimit.limiter.UserRateLimiter;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: beacon-cloud
 * @Package: com.superbytecode.cloud.safety.ratelimit
 * @ClassName: RateLimitFactory
 * @Description: [限流器工厂]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/13 16:24
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
public class RateLimitFactory {
    private RateLimitFactory() {
    }

    public static RateLimiter bind(RateLimitType type) {
        RateLimiter rateLimiter;
        switch (type) {
            case IP:
                rateLimiter = new IPRateLimiter();
                break;
            case USER:
                rateLimiter = new UserRateLimiter();
                break;
            case CUSTOM:
                rateLimiter = new CustomRateLimiter();
                break;
            default:
                throw new RateLimitException("Unsupported rate limiter type: " + type);
        }
        return rateLimiter;
    }
}